package mt

import (
	"awesomeProject2/product"
	"awesomeProject2/write_line"
	"fmt"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
)

func WriteFileMt() {
	files, err := ioutil.ReadDir("C:\\Users\\admin\\GolandProjects\\waimaigo\\json\\product_mt\\")
	if err != nil {
		log.Fatal(err)
	}

	cp := make([]string, 0)
	//price := make([]string, 0)
	//activity := make([]string, 0)

	for _, file := range files {
		producrts := product.GetProductMt("C:\\Users\\admin\\GolandProjects\\waimaigo\\json\\product_mt\\" + file.Name())

		for _, datum := range producrts.Data.ProductList {
			//println(datum.Title + "=" + strconv.Itoa(int(datum.Price)) + "=" + strconv.Itoa(int(datum.MinActivePrice)))
			cp = append(cp, datum.Name)
			//price = append(price, strconv.Itoa(int(datum.WmProductSkus[0].Price)))
			//activity = append(activity, strconv.Itoa(int(datum.WmProductSkus[0].Price)))
		}
	}

	write_line.WriteLineTxm(cp, "C:\\Users\\Admin\\go\\src\\awesomeProject2\\mt\\产品.txt")
	//write_line.WriteLineTxm(price, "C:\\Users\\Admin\\go\\src\\awesomeProject2\\mt\\price.txt")
	//write_line.WriteLineTxm(activity, "C:\\Users\\Admin\\go\\src\\awesomeProject2\\mt\\activity.txt")
}

func GetFileMt() []product.ProductMt {
	files, err := ioutil.ReadDir("C:\\Users\\admin\\GolandProjects\\waimaigo\\json\\product_mt\\")
	if err != nil {
		log.Fatal(err)
	}

	mts := make([]product.ProductMt, 0)

	for _, file := range files {
		producrts := product.GetProductMt("C:\\Users\\admin\\GolandProjects\\waimaigo\\json\\product_mt\\" + file.Name())
		mts = append(mts, producrts)
	}
	return mts
}

func GetFileMtNewProducts() []product.Sputag {
	strings := make([]string, 0)
	err := filepath.Walk("C:\\Users\\admin\\GolandProjects\\waimaigo\\json\\new_product\\",
		func(path string, info os.FileInfo, err error) error {
			if err != nil {
				return err
			}
			if info.IsDir() {
				return nil
			}
			fmt.Println(path)
			strings = append(strings, path)
			return nil
		})
	if err != nil {
		log.Println(err)
	}

	stgs := make([]product.Sputag, 0)

	for _, fileStr := range strings {
		mtCopy := product.GetProductMtCopy(fileStr)
		stgs = append(stgs, mtCopy)
	}

	return stgs
}
